package com.heima.homeservicemanagementsystem.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import  com.heima.homeservicemanagementsystem.module.PageParams;
import  com.heima.homeservicemanagementsystem.module.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import com.heima.homeservicemanagementsystem.entity.UserFeedback;
import com.heima.homeservicemanagementsystem.service.UserFeedbackService;
import java.util.List;
import static cn.dev33.satoken.SaManager.log;

/**
 * 用户反馈;(user_feedback)表控制层
 * @author : http://www.chiner.pro
 * @date : 2025-4-17
 */
@Tag(name = "用户反馈对象功能接口")
@RestController
@RequestMapping("/userFeedback")
public class UserFeedbackController{

    @Resource
    private UserFeedbackService userFeedbackService;

    @Operation(summary="分页查询")
    @PostMapping("/page")
    public Result<Page<UserFeedback>> paginQuery(@RequestBody PageParams<UserFeedback> pageParams){
        //查询参数
        UserFeedback params =pageParams.getParams();
        LambdaQueryWrapper <UserFeedback> lqw =new LambdaQueryWrapper<>();



        lqw.eq(params.getUserId()!=null,UserFeedback::getUserId,params.getUserId());





        lqw.eq(params.getCallName()!=null,UserFeedback::getCallName,params.getCallName());


        lqw.eq(params.getContactInformation()!=null,UserFeedback::getContactInformation,params.getContactInformation());

        return Result.success(userFeedbackService.page(pageParams.getPage(),lqw));
    }


    @Operation(summary = "用户反馈所有搜索")
    @GetMapping("/list")
    public Result searchQuery() {
        return Result.success(userFeedbackService.list());
    }
    @Operation(summary = "有条件的搜索")
    @PostMapping("/tjSearch")
    public Result Query(@RequestBody UserFeedback  userFeedback) {
        LambdaQueryWrapper<UserFeedback> lqw = new LambdaQueryWrapper<>();


        lqw.eq(userFeedback.getId()!=null,UserFeedback::getId,userFeedback.getId());


        lqw.eq(userFeedback.getUserId()!=null,UserFeedback::getUserId,userFeedback.getUserId());




        lqw.like(userFeedback.getCallName()!=null,UserFeedback::getCallName,userFeedback.getCallName());


        lqw.eq(userFeedback.getContactInformation()!=null,UserFeedback::getContactInformation,userFeedback.getContactInformation());


        return Result.success(userFeedbackService.list(lqw));
    }

    /**
     * 新增数据
     *
     * @param userFeedback 实例对象
     * @return 实例对象
     */
    @Operation(summary="新增数据")
    @PostMapping("/insert")
    public Result<Boolean> insert(@RequestBody UserFeedback userFeedback){
        if(userFeedbackService.save(userFeedback)){
            return Result.success();
        }
        return Result.error();
    }

    /**
     * 更新数据
     *
     * @param userFeedback 实例对象
     * @return 实例对象
     */
    @Operation(summary="更新数据")
    @PutMapping("update")
    public Result<Boolean> update(@RequestBody UserFeedback userFeedback){
        if(userFeedbackService.updateById(userFeedback)){
            return Result.success();
        }
        return Result.error();
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Operation(summary="通过主键删除数据",
            parameters={
                    @Parameter(name ="id",description="主键",required =true,in=ParameterIn.PATH)
            })
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteById(@PathVariable String id){

        if(userFeedbackService.removeById(id)){
            return Result.success();
        }
        return Result.error();
    }

    @Operation(summary = "多id删除数据")
    @DeleteMapping("/delete")
    public Result<Boolean> deleteByIds(@RequestBody List<String> id) {
        log.info("前端信息：{}", id);
        if (userFeedbackService.removeByIds(id)) {
            return Result.success();
        }
        return Result.error();
    }
}